Date.prototype.Format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S": this.getMilliseconds()
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

Date.prototype.DateAdd = function(interval,number) {
	var _date = this;

	var o = {
		"y" : _date.getFullYear(),
		"m" : _date.getMonth(),
		"d" : _date.getDate()
	};
	var n = {
		"y" : o["y"],
		"m" : o["m"],
		"d" : o["d"]
	};

	switch (interval) {
		case "y":
			n[interval] = n[interval] + number;

			break;
		case "m":
			if (n[interval] <= Math.abs(number)) {
				var diffNum = Math.abs(number);

				while (diffNum > 0) {
					var _chkDiffMonth1 = new Date(n["y"],0,1).getMonth();
					var _chkDiffMonth2 = new Date(n["y"],n["m"],1).getMonth();

					var _chkDiffMonth = _chkDiffMonth2 - _chkDiffMonth1;

					if (diffNum > _chkDiffMonth) {
						diffNum -= _chkDiffMonth + 1;

						n["y"] = n["y"] - 1;
						n[interval] = 11;
					} else {
						n[interval] = _chkDiffMonth2 - diffNum;

						diffNum = 0;
					}

					var _chkDate1 = new Date(n["y"],n["m"],1);
					var _chkDate2 = new Date(n["y"],n["m"],n["d"]);

					while ( _chkDate1.getMonth() !== _chkDate2.getMonth() ) {
						n["d"] = n["d"] - 1;
						_chkDate2 = new Date(n["y"],n["m"],n["d"]);
					}
				}
			}

			break;
		case "d":
			if (n[interval] <= Math.abs(number)) {
				var diffNum = Math.abs(number);

				while (diffNum > 0) {
					var _chkDiffDate1 = new Date(n["y"],n["m"],1).getDate();
					var _chkDiffDate2 = new Date(n["y"],n["m"],n["d"]).getDate();

					var _chkDiffDate = _chkDiffDate2 - _chkDiffDate1;

					if (diffNum > _chkDiffDate) {
						diffNum -= _chkDiffDate + 1;

						n["m"] = n["m"] - 1;

						if (n["m"] < 0) {
							n["y"] = n["y"] - 1;
							n["m"] = 11;
						}

						n[interval] = 31;

						var _chkDate1 = new Date(n["y"],n["m"],1);
						var _chkDate2 = new Date(n["y"],n["m"],n["d"]);

						while ( _chkDate1.getMonth() !== _chkDate2.getMonth() ) {
							n["d"] = n["d"] - 1;
							_chkDate2 = new Date(n["y"],n["m"],n["d"]);
						}
					} else {
						n[interval] = _chkDiffDate2 - diffNum;

						diffNum = 0;
					}
				}
			}

			break;
		default:
			break;
	}

	return new Date(n["y"],n["m"],n["d"]);
}